<template>
  <view>
    <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权手机号</button>
  </view>
</template>

<script>
import { registerApi } from '../../../api/user/login'
import {toast} from "../../../utils";
const app = getApp()
export default {
  name: 'Register',
  methods: {
    getPhoneNumber(e) {
      if (e.detail.code) {
        registerApi({ code: e.detail.code }).then(response => {
          if (response.data.openId && response.data.openId !== '') {
            uni.setStorage({ key: 'openId', data: response.data.openId })
          }
          if (response.data.unionId && response.data.unionId !== '') {
            uni.setStorage({ key: 'unionId', data: response.data.unionId })
          }
          if (response.data.sid && response.data.sid !== '') {
            uni.setStorageSync('sid', response.data.sid)
            // _this.$store.commit('referer/setSid', response.data.sid)
          }
          if (response.data.token && response.data.token !== '') {
            uni.setStorageSync('token', response.data.token)
            app.getUserInfo()
          }
        })
      } else {
        toast('请授权手机号码，以便我们为您提供更好的服务')
      }
      console.log('e', e)
    }
  }
}
</script>

<style scoped>

</style>
